package com.Controller;

import com.Bean.User;
import com.Common.CodeMsg;
import com.Common.Constant;
import com.Common.Result;
import com.Util.RespUtil;
import org.junit.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/4/28 20:38
 */
@WebServlet("/page.do")
public class PageServlet extends HttpServlet {

    private static final long serialVersionUID = -2965553505477722591L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String page = req.getParameter("page");
        try {
            this.getClass().getDeclaredMethod(page,HttpServletRequest.class,HttpServletResponse.class).
                    invoke(this,req,resp);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
    protected void main(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/main.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void userList(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/User/list.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void addUser(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/User/addUser.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void goodList(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/Good/list.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void addEmp(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/employee/addEmp.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void salesOrderst(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/SealOrderlist.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void purchaseOrders(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/purchaseOrderlist.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void console(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/console.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void addPurchaseOrder(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/purchaseOrder.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    protected void addSealOrder(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/salesOrder.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void addNewGoods(HttpServletRequest req,HttpServletResponse resp){
        try {
            req.getRequestDispatcher("WEB-INF/jsp/AddNewGoods.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
